<!DOCTYPE >
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <style>
        body {
            background: url("img/timg1.jpg");
        }

        .form-signin {
            max-width: 500px;
            padding: 15px;
            margin: 100px auto;
            background: rgba(233, 233, 233, 0.3);
            border-radius: 6px;
            color: white;
            text-align: center;
            color: #222;
        }

        .form-signin img {
            float: left;
        }
    </style>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="layer/layer.js"></script>
</head>
<body>
<div class="container" id="app">
    <form class="form-horizontal form-signin">
        <h2 class="form-signin-heading">资源管理系统</h2>
        <br>
        <br>
        <div class="form-group">
            <label for="inputEmail3" class="col-xs-2 control-label">账号</label>
            <div class="col-xs-10">
                <input type="text" class="form-control" id="inputEmail3" v-model="loginName" placeholder="登录名" required>
            </div>
        </div>
        <div class="form-group">
            <label for="inputPassword3" class="col-xs-2 control-label">密码</label>
            <div class="col-xs-10">
                <input type="password" class="form-control" id="inputPassword3" v-model="loginPassword" placeholder="密码"
                       required>
            </div>
        </div>

        <div class="form-group">
            <label for="inputPassword4" class="col-xs-2 control-label">验证码</label>
            <label for="inputPassword4" class="col-xs-4"><img src="verify"
                                                              onclick="this.src='verify?'+Math.random()"></label>
            <div class="col-xs-6">
                <input type="text" class="form-control" id="inputPassword4" v-model="verify" placeholder="验证码" required>
            </div>
        </div>
        <br>
        <div class="form-group">
            <div class="col-xs-12">
                <p style="color: red">{{message}}</p>
                <!-- {{}}  差值表达式 -->
                <button type="button" class="btn btn-success btn-block btn-lg" @click="login()">登录</button>
                <button type="button" class="btn btn-danger btn-block btn-lg" @click="add()">注册</button>
            </div>
        </div>
    </form>
</div>

<script>
    new Vue({
        //挂载
        el: "#app",
        data: {
            message: '',
            loginName: "zdn",
            loginPassword: "123",
            verify: ""
        },
        methods: {
            //添加用户
            add() {
                var vm = this;
                layer.open({
                    type: 2,
                    title: '用户添加',
                    shadeClose: false,  //阴影
                    shade: 0.5,  //透明度
                    area: ['600px', '100%'],
                    content: 'userAdd.html', //iframe的url
                    end: function () {
                        vm.loadData();
                    }
                });
            },
            // methods 方法   写方法的地方
            //登录
            login() {
                var vm = this;
                $.post("/login", {
                    verify: this.verify,
                    loginName: this.loginName,
                    loginPassword: this.loginPassword
                }, function (response) {
                    if (response.code == 200) {
                        // alert("登陆成功！")
                        layer.alert('登陆成功！！',{
                            icon: 1,
                            skin: 'layer-ext-moon' ,
                            time: 2000,
                            end:function () {
                                location.href = "index.html"
                                //正确的话进入下一个页面
                            }
                        })
                    } else {
                        vm.message = response.msg;
                    }
                })
            }
        }
    })
</script>
</body>
</html>